import java.util.Stack;

class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> minStack;

    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(!minStack.empty()){
            if(val <= minStack.peek()){
                minStack.push(val);
            }
        }else{
            minStack.push(val);
        }
    }

    public void pop() {
        if(!stack.empty()){
            int num = stack.pop();
            if(minStack.peek() == num){
                minStack.pop();
            }
        }

    }

    public int top() {
        if(stack.empty()){
            return -1;
        }
        return stack.peek();
    }

    public int getMin() {
        if(minStack.empty()){
            return -1;
        }
        return minStack.peek();
    }
}
